{% extends "personal_center/base.html" %}

{% block page_link %}
    <link rel="stylesheet" href="../../static/system_setup/css/style.css">
    <link rel="stylesheet" type="text/css" href="../../static/personal_center/css/index.css">
    <link rel="stylesheet" type="text/css" href="../../static/personal_center/css/common.css">
    <script type="text/javascript" src="../../static/personal_center/js/index.js"></script>
{% endblock %}


{% block style %}
    <style>
        .add_class {
            background: #1E90FF;
        }

        .top_tag {
            border-bottom: #01AAED solid 2px;
            color: #01AAED;
        }

        .tab_top {
            width: 100px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            display: inline-block;
            cursor: pointer;
        }

        .file {
            position: relative;
            display: inline-block;
            background: #D0EEFF;
            border: 1px solid #99D3F5;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            color: #1E88C7;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
        }

        .file input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }

        .file:hover {
            background: #AADFFD;
            border-color: #78C3F3;
            color: #004974;
            text-decoration: none;
        }

        .input-style {
            display: inline-block;
            width: 100%;
            height: 35px;
            font-size: 14px;
            border: none;
            background: white;
        }
        .shade {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(36, 36, 36, 0.5);
            display: none;
            z-index: 10000;
        }
    </style>
{% endblock %}


{% block right_content %}
    <div id="new_models1" class="shade">
        <div id="new_models" style="width: 100%;height: 100%;position: absolute;">
            <div style="width: 500px;height: 200px;background: #F5F5F5;z-index: 10000;position: absolute;top: 50%;left: 50%;transform:translate(-50%,-50%);border-radius: 3px;border: #dfdfdf solid 1px;">
                <div id="box" style="width: 100%;height: 40px;background: #f4f7fa;cursor: move;border-top-left-radius: 5px;border-top-right-radius: 5px;line-height: 50px;border-bottom: #dfdfdf solid 1px;">
                    <div style="width: 20%;margin-left: 1%;display: inline-block;line-height: 0px;">
                        <h5 id="modal-title" class="modal-title" style="color: #727E8C;">
                            添加备注
                        </h5>
                    </div>
                    <span onclick="close_models()" style="float: right;padding-right: 2%;cursor: pointer;">
                        <i class="iconfont icon-quchu"></i>
                    </span>
                </div>
                <div style="height: 120px;width: 100%;border-bottom: #dfdfdf solid 1px;">
                    <textarea name="" id="remarks" cols="30" rows="10" style="width: 96%;height: 100px;margin-left: 2%;border: #cfcfcf solid 1px;outline: none;"></textarea>
                </div>
                <div style="width: 100%;height: 40px;text-align: right;padding-right: 2%;">
                    <button id="summit_but" style="width: 70px;height: 30px;border: #dfdfdf solid 1px;margin-top: 5px;border-radius: 3px;background: #1E90FF;color: white;">
                        提交
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div style="width: 100%;height: 40px;background: white;border-bottom: #A9A9A9 solid 0.5px;line-height: 40px;padding-left: 1%;color: black;">
        <div id="DW_tag" class="tab_top top_tag">
            来文拟稿
        </div>

        <div id="summit_button" style="height: 100%;display: inline-block;float: right;padding-right: 15px;">
            <button id="summ_id" onclick="summit_fun()" style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;color: white;background-color: #1E90FF;line-height: 25px;">提交</button>
        </div>

        <div class="sa-ele" id="SearchButton" style="font-size: 0;height: 100%;display: none;float: right;padding-right: 15px;">
            <input type="text" id="search_value" name="search_val" style="width: 300px;display: inline-block;border-bottom-left-radius: 3px;border-top-left-radius: 3px;height: 30px;border: #0d8ddb solid 1px;vertical-align: top;font-size: 14px;padding-left: 2px;margin-top: 5px;" placeholder="请输入搜索关键词">
            <button class="search-action" style="width: 100px;height: 30px;border-bottom-right-radius: 3px;border-top-right-radius: 3px;display: inline-block;font-size: 14px;border: #0d8ddb solid 1px;border-left: none;background: #0d8ddb;color: white;margin-top: 5px;line-height: 10px;margin-left: -1px;">搜索</button>
        </div>
        <div id="del_button" style="width: 7%;text-align: center;height: 100%;line-height: 40px;float: right;display: none">
            <button onclick="ConfirmDelete()" data-toggle="modal" data-target=".bd-example-modal-sm"
                    style="height: 30px;width: 90%;border-radius: 3px;" type="button"
                    class="btn btn-danger add-station1">删除
            </button>
        </div>
    </div>

    <div id="DW" style="width: 100%;height: 95%;background: white;">
        <div style="width: 100%;height: 40px;line-height: 50px;text-align: center;">
            <h3 id="manuscript_title" style="line-height: 50px;">电 文 处 理 及 阅 文 笺</h3>
        </div>
        <hr>
        <div style="width: 90%;margin-left: 5%;height: 90%;overflow: auto;margin-top: 1%;border-top: #cccccc solid 1px;">
            <div style="width: 100%;">
                <table style="width: 100%;">
                    <tr style="width: 100%;">
                        <td style="width: 15%;height: 40px;line-height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">接收科室</td>
                        <td id="ngks" style="width: 15%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;">{{ department }}</td>
                        <td style="width: 15%;height: 40px;line-height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">接收人</td>
                        <td id="ngr" style="width: 20%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;">{{ realname }}</td>
                        <td style="width: 10%;height: 40px;line-height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">来函编号</td>
                        <td id="swbh" style="width: 25%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;">{{ lw_count }}</td>
                    </tr>
                </table>
                <table style="width: 100%;">
                    <tr style="width: 100%;">
                        <td style="width: 15%;height: 40px;line-height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;"><span style="color: red;">* </span>来函单位</td>
                        <td id="lwdw" style="width: 85%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;" contenteditable="true"></td>
                    </tr>
                    <tr style="width: 100%;">
                        <td style="width: 15%;height: 40px;line-height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;"><span style="color: red;">* </span>来函字号</td>
                        <td id="lwzh" style="width: 85%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;" contenteditable="true"></td>
                    </tr>
                    <tr style="width: 100%;">
                        <td style="width: 15%;height: 40px;line-height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;"><span style="color: red;">* </span>来函日期</td>
                        <td id="swrq" style="width: 85%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;">
                            <input class="input-style" type="text" name="car_start" id="car_start" autocomplete="off">
                        </td>
                    </tr>
                    <tr style="width: 100%;">
                        <td style="width: 15%;height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;"><span style="color: red;">* </span>标&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题</td>
                        <td id="gwbt" style="width: 85%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;" contenteditable="true"></td>
                    </tr>
                    <tr style="width: 100%;">
                        <td style="width: 15%;height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;"><span style="color: red;">* </span>内&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;容</td>
                        <td id="gwnr" style="width: 85%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;" contenteditable="true"></td>
                    </tr>
                    {% if charge_flag %}
                        <tr style="width: 100%;">
                            <td style="width: 15%;height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;"><span style="color: red;">* </span>分管领导</td>
                            <td style="width: 85%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;">
                                <select name="" id="leaders" style="width: 100%;height: 100%;border: none;outline: none;">
                                    <option value="0">请选择分管领导</option>
                                    {% for foo in leaders_obj %}
                                        <option value="{{ foo.id }}">{{ foo.real_name }}</option>
                                    {% endfor %}
                                </select>
                            </td>
                        </tr>
                    {% endif %}
                    <tr style="width: 100%;">
                        <td style="width: 15%;height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">标注文本</td>
                        <td id="bzwb" style="width: 85%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;" contenteditable="true"></td>
                    </tr>
                    <tr style="width: 100%;">
                        <td style="width: 15%;height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">时间期限</td>
                        <td id="sjqx" style="width: 85%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;" contenteditable="true"></td>
                    </tr>
                    <tr style="width: 100%;">
                        <td style="width: 15%;height: 40px;border: #cccccc solid 1px;text-align: right;padding-right: 1%;border-top: none;">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注</td>
                        <td id="beizhu" style="width: 85%;height: 40px;line-height: 40px;border: #cccccc solid 1px;border-left: none;padding-left: 1%;border-top: none;outline: none;" contenteditable="true">

                        </td>
                    </tr>
                </table>
            </div>
            <div style="width: 100%;">
                <div style="width: 100%;height: 40px;line-height: 40px;background-color: #F5F5F5;color: #1E90FF;padding-left: 1%;border: #cccccc solid 1px;border-top: none;border-bottom: none;padding-right: 1%;">
                    <span style="color: red;">* </span>上传文件
                    <a href="javascript:;" class="file" style="vertical-align: top;margin-top: 5px;float: right;">
                        上传文件
                        <input type="file" name="regular_main_body" id="regular_main_body" onchange="upload_accessory('file1', 'regular_main', 'regular_main_body')">
                    </a>
                </div>
                <table style="width: 100%;">
                    <thead>
                        <tr>
                            <td style="width: 5%;border: #cccccc solid 1px;text-align: center;">序号</td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">文件名称</td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">文件大小</td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">上传时间</td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">上传人员</td>
                            <td style="width: 15%;border: #cccccc solid 1px;border-left: none;text-align: center;">操作</td>
                        </tr>
                    </thead>
                    <tbody style="overflow: auto;" id="regular_main"></tbody>
                </table>
            </div>
        </div>
    </div>

    <div id="XZ" style="width: 100%;height: 94%;background: white;display: none;">
        <!--确认删除？-->
        <div class="modal fade bd-example-modal-sm" tabindex="-1" role="dialog" aria-hidden="true">
            <div class="modal-dialog modal-sm" style="margin-top: 20%;">
                <div class="modal-content" style="height: 100px;border-radius: 7px;width: 300px;background: #F8F8FF;">
                    <div class="modal-body" style="height: 50px;line-height: 50px;text-align: center;">
                        <p id="Confirm-content" style="margin-left: 2%;letter-spacing:1px;"></p>
                    </div>
                    <div class="modal-footer" style="height: 40px;">
                        <button id="close-model2" type="button" class="btn btn-secondary" data-dismiss="modal"
                                style="height: 30px;line-height: 30px;border-radius: 3px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;取&nbsp;消&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        </button>
                        <button type="button" class="btn btn-primary"
                                style="margin-left: 2%;margin-right: 2%;height: 30px;line-height: 30px;border-radius: 3px;"
                                onclick="DeleteData()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;确&nbsp;认&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        </button>
                    </div>
                </div>
            </div>
        </div>
        <div id="my_application" style="width: 100%;height: 100%;overflow: auto;background-color: white;">
            <div class="right-box" style="width: 100%;height: 100%;margin-top: 0;">
                <div style="height: 100%;width: 100%;overflow: auto;border-bottom: #cccccc solid 1px;background-color: white;">
                    <section class="grid-main" style="height: calc(100vh - 108px);">
                        <table id="main_table"></table>
                    </section>
                </div>
            </div>
        </div>
    </div>
{% endblock %}


{% block script %}
    <script type="text/javascript" src="../../static/administrative/js/other/jquery.js"></script>
    <script src="../../static/administrative/layDate-v5.0.9/laydate/laydate.js"></script> <!-- 改成你的路径 -->
    <script type="text/javascript" src="../../static/administrative/js/layer.js"></script>
    <script>
        window.onload = function () {
            document.getElementById("sponsor").className = "add_class";
            document.getElementById("personage").className = "add-nav-active";
        };

        const uuid = "{{ uuid | safe }}"

        lay('#version').html('-v' + laydate.v);
        //执行一个laydate实例
        laydate.render({
            elem: '#car_start' //指定元素
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#car_end' //指定元素
        });

        function upload_accessory(file_type, tbody_id, accessory_type) {
            document.getElementById("loading").style.display = "inline-block";
            var swbh = document.getElementById("swbh").innerText;
            var form = new FormData();
            var files = document.getElementById(accessory_type).files[0];
            form.append(file_type, files);
            form.append('number', uuid);
            form.append("source", "lh")
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/topics_attachments_upload", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        creat_table(JsonDate, tbody_id)
                    }
                }
            };
        }

        // 创建附件列表
        function creat_table(JsonData, tbody_id) {
            var t_table = document.getElementById(tbody_id);
            var local_host = window.location.host;
            if (Array.isArray(JsonData["pdf_path"])){
                for (var i=0; i<JsonData["pdf_path"].length; i++){
                    var tr = document.createElement("tr");
                    var td1 = document.createElement("td");var td2 = document.createElement("td");var td3 = document.createElement("td");var td4 = document.createElement("td");var td5 = document.createElement("td");var td6 = document.createElement("td");
                    td1.innerHTML = t_table.children.length+1;td1.style.textAlign = "center";td1.style.border="#cccccc solid 1px";td1.style.borderTop="none";
                    td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border="#cccccc solid 1px";td2.style.borderLeft="none";td2.style.borderTop="none";
                    td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border="#cccccc solid 1px";td3.style.borderLeft="none";td3.style.borderTop="none";
                    td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border="#cccccc solid 1px";td4.style.borderLeft="none";td4.style.borderTop="none";
                    td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border="#cccccc solid 1px";td5.style.borderLeft="none";td5.style.borderTop="none";
                    td6.innerHTML = "<a target='_blank' href='"+JsonData["pdf_path"][i]["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \""+tbody_id+"\", \""+JsonData["pdf_path"][i]["id"]+"\")'>删除</a>";td6.style.textAlign = "center";td6.style.border="#cccccc solid 1px";td6.style.borderLeft="none";td6.style.borderTop="none";
                    tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);
                    t_table.appendChild(tr);
                }
                if (JsonData["pdf_path"].length > 1){
                    document.getElementById("del_adjunct").style.display='block';
                }
            }else {
                tr = document.createElement("tr");
                td1 = document.createElement("td");td2 = document.createElement("td");td3 = document.createElement("td");td4 = document.createElement("td");td5 = document.createElement("td");td6 = document.createElement("td");
                td1.innerHTML = t_table.children.length+1;td1.style.textAlign = "center";td1.style.border="#cccccc solid 1px";td1.style.borderTop="none";
                td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border="#cccccc solid 1px";td2.style.borderLeft="none";td2.style.borderTop="none";
                td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border="#cccccc solid 1px";td3.style.borderLeft="none";td3.style.borderTop="none";
                td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border="#cccccc solid 1px";td4.style.borderLeft="none";td4.style.borderTop="none";
                td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border="#cccccc solid 1px";td5.style.borderLeft="none";td5.style.borderTop="none";
                td6.innerHTML = "<a target='_blank' href='"+JsonData["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \""+tbody_id+"\", \""+JsonData["id"]+"\")'>删除</a>";td6.style.textAlign = "center";td6.style.border="#cccccc solid 1px";td6.style.borderLeft="none";td6.style.borderTop="none";
                tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);
                t_table.appendChild(tr);
            }
        }

        function summit_fun() {
            var charge_flag = "{{ charge_flag | safe }}";
            var leaders_people = "";
            var ngks = document.getElementById("ngks").innerText;           // 拟稿科室
            var ngr = document.getElementById("ngr").innerText;             // 拟稿人
            var swbh = document.getElementById("swbh").innerText;           // 收文编号
            var lwdw = document.getElementById("lwdw").innerText;           // 来文单位
            var lwzh = document.getElementById("lwzh").innerText;           // 来文字号
            var swrq = document.getElementById("car_start").value;          // 收文日期
            var gwbt = document.getElementById("gwbt").innerText;           // 收文标题
            var gwnr = document.getElementById("gwnr").innerText;           // 收文内容
            var bzwb = document.getElementById("bzwb").innerText;           // 标注文本
            var sjqx = document.getElementById("sjqx").innerText;           // 时间期限
            var beizhu = document.getElementById("beizhu").innerText;       // 来文备注

            if (!lwdw) {
                alert("来文单位不能为空！")
                return false
            } else if (!lwzh) {
                alert("来文字号不能为空！")
                return false
            } else if (!swrq) {
                alert("收文日期不能为空！")
                return false
            } else if (!gwbt) {
                alert("标题不能为空！")
                return false
            } else if (!gwnr) {
                alert("内容不能为空！")
                return false
            }

            if (charge_flag === "True") {
                leaders_people = document.getElementById("leaders").value;
                if (leaders_people === "0") {
                    alert("请选择分管院长！")
                    return false
                }
            }
            var t_table = document.getElementById('regular_main').childNodes.length;
            if (t_table === 0) {
                alert("请上传正文！")
                return false
            }

            document.getElementById("loading").style.display = "inline-block";
            var send_str = "send_number="+String(lwzh)+"&recive_number="+swbh+"&send_company="+lwdw+"&recive_time="+swrq+"&title="+gwbt+"&content="+gwnr+"&annotated_text="+bzwb+"&time_limit="+sjqx+"&uuid="+uuid+"&beizhu="+beizhu+"&leaders_people="+leaders_people+"&charge_flag="+charge_flag;
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/personal-center/ExternalCorrespondenceIndex.html", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send(send_str);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        alert("创建成功！")
                        window.location.href = 'ExternalCorrespondenceList.html';
                    }
                }
            };
        }

        function RemoveTr(_this, tbody_id, wj_id) {
            var table = document.getElementById(tbody_id);
            var trNode = $(_this).parent().parent();
            trNode.remove();

            for (var i=0; i<table.children.length; i++){
                table.children[i].children[0].innerHTML=i+1;
            }

            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/delete_attachments_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("id="+String(wj_id));
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        alert("删除成功！")
                    }
                }
            };
        }

        const gridManagerName = "test",
            TYPE_MAP = {1: "HTML/CSS", 2: "nodeJS", 3: "javaScript", 4: "前端鸡汤", 5: "PM Coffee", 6: "前端框架", 7: "前端相关"},
            arg = {
                gridManagerName: "test",
                width: "100%",
                height: "100%",
                autoOrderConfig: {fixed: "left"},
                checkboxConfig: {key: "id", fixed: "left"},
                supportAjaxPage: !0,
                sortMode: "single",
                supportMenu: !0,
                menuHandler: e => (e.unshift({
                    content: "自定义菜单", line: !0, onClick: e => {
                        alert(e)
                    }
                }), e),
                useCellFocus: !0,
                useHideRow: !0,
                supportMoveRow: !0,
                moveRowConfig: {
                    key: "priority", useSingleMode: !0, fixed: "left", handler: (e, t) => {
                        console.log(e, t)
                    }
                },
                disableCache: !1,
                ajaxData: function (e, t) {
                    var local_host = window.location.host;          // 获取当前IP
                    return "/personal-center/official_documents_list_view"
                },
                exportConfig: {
                    fileName: e => {
                        const t = new Date;
                        let a = `${t.getFullYear()}-${t.getMonth() + 1}-${t.getDate()}`;
                        for (let t in e) a = `${a}-${t}=${e[t]}`;
                        return a
                    }, suffix: "xls"
                },
                ajaxType: "POST",
                checkedBefore: function (e, t, a) {
                    return console.log("checkedBefore==", e, t, a), a && 90 === a.id && alert("该节点在checkedBefore中配置为不可选"), a && 90 !== a.id
                },
                responseHandler: e => (e.data.forEach((e => {
                    e.priority = e.id
                })), e),
                rowRenderHandler: (e, t) => e,
                emptyTemplate: e => `<div style="text-align: center;">${e.query.title ? "搜索为空" : "暂无数据"}</div>`,
                columnData: [
                    {
                        key: "title",
                        text: "来文题目",
                        align: "center",
                        disableMoveRow: !0
                    }, {
                        key: "send_company",
                        text: "来文单位",
                        align: "center",
                    }, {
                        key: "create_time",
                        text: "申请时间",
                        align: "center",
                    }, {
                        key: "send_number",
                        text: "来文字号",
                        align: "center",
                    },{
                        key: "recive_number",
                        text: "收文编号",
                        align: "center",
                    }, {
                        key: "state",
                        text: "当前节点",
                        align: "center",
                    }, {
                        key: "current_audit_user",
                        text: "当前审核人",
                        align: "center",
                    }, {
                        key: "action",
                        width: "150px",
                        align: "center",
                        fixed: "right",
                        disableMoveRow: !0,
                        disableRowCheck: !0,
                        text: '<span style="color: red">操作</span>',
                        template: (e, t) => `<a class="plugin-action" id="${t.id}" href="javascript:;" onclick="">${t.url}</a>`
                    }]
            }, demo1 = {
                initSearch: function () {
                    document.querySelector(".search-action").addEventListener("click", (function () {
                    var data_value = document.getElementById("search_value").value;
                    var e = {
                        search_data: data_value,
                    };
                    table.GM("setQuery", e, (function () {
                        console.log("setQuery执行成功")
                    }))
                }))
                }, initFN: () => {

                }, initGM: function () {
                    new window.GridManager(table, arg, (e => {
                        console.log("渲染完成后的回调函数:", e), console.log(arg.columnData)
                    }))
                }, editRowData: function (e) {
                    window.GridManager.updateRowData("test", "id", {
                        id: window.parseInt(e.getAttribute("data-id")),
                        lastDate: (new Date).getTime()
                    })
                }
            }, table = document.querySelector("#main_table");
        demo1.initSearch(table), demo1.initGM(table), demo1.initFN();
        const table_name = '{{ table_name }}'

        function del_draft(id_0) {
            var id = id_0
            var r = confirm("确认删除？")
            if (r == true) {
                var xhr = new XMLHttpRequest();
                var local_host = window.location.host;          // 获取当前IP
                xhr.open('post', "/administrative/delete_draft_view", true);
                xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
                xhr.send("id=" + id + "&table_name=" + table_name);
                xhr.onreadystatechange = function () {
                    if (xhr.readyState === 4) {
                        if (xhr.status === 200) {
                            document.getElementById("loading").style.display = "none";
                            var JsonDate = JSON.parse(xhr.responseText);
                            alert(JsonDate['message'])
                            window.location.reload();
                        }
                    }
                };
            }
        }

        function ConfirmDelete() {
            var myArray = []
            var check_box_list = document.getElementsByClassName("gm-radio-checkbox-input gm-checkbox-input");
            for (var t = 0; t < check_box_list.length - 1; t++) {
                if (check_box_list[t].checked) {
                    var remove_id = check_box_list[t].parentNode.parentNode.parentNode.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.id;
                    myArray.push(remove_id)
                }
            }
            if (myArray.length === 0) {
                document.getElementById("Confirm-content").innerHTML = "没有选择删除的流程！";
            } else {
                document.getElementById("Confirm-content").innerHTML = "确认要删除这" + String(myArray.length) + "个流程吗？"
            }
        }


        // 批量删除数据
        function DeleteData() {
            var myArray = []
            var check_box_list = document.getElementsByClassName("gm-radio-checkbox-input gm-checkbox-input");
            for (var t = 0; t < check_box_list.length - 1; t++) {
                if (check_box_list[t].checked) {
                    var remove_id = check_box_list[t].parentNode.parentNode.parentNode.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.id;
                    myArray.push(remove_id)
                }
            }
            if (myArray.length === 0) {
                document.getElementById("close-model2").click();
                return myArray
            }
            console.log("myArray: ", JSON.stringify(myArray))
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/delete_in_batches", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("delete_list=" + JSON.stringify(myArray) + "&table_name=" + table_name);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonDate = JSON.parse(xhr.responseText);
                        alert(JsonDate["message"]);
                        window.location.reload();
                    }
                }
            };
        }

        function model_inlone(ele_id) {
            document.getElementById("new_models1").style.display = "inline-block";
            document.getElementById("summit_but").setAttribute("onclick", "commit_remake('"+ele_id+"')");
        }

        function close_models() {
            document.getElementById("new_models1").style.display = "none";
        }

        let title = document.querySelector("#box");
        let addForm = document.querySelector("#new_models");

        title.addEventListener("mousedown", function (e) {
            let x = e.pageX - addForm.offsetLeft;
            let y = e.pageY - addForm.offsetTop;

            document.addEventListener("mousemove", move);
            function move(e) {
                addForm.style.left = e.pageX - x + 'px';
                addForm.style.top = e.pageY - y + 'px';
            }

            document.addEventListener("mouseup", function (e) {
                document.removeEventListener("mousemove", move);
            })
        });

        // 提交备注
        function commit_remake(ele_id) {
            var remarks = document.getElementById("remarks").value;
            if (!remarks) {
                alert("请填写备注！")
                return false
            }
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/personal-center/Comments", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("received_id=" + String(ele_id)+"&remarks="+remarks);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate['code'] === 200) {
                            console.log('JsonDate', JsonDate)
                            alert('添加成功！')
                            window.location.reload();
                        } else {
                            alert(JsonDate['message'])
                            window.location.reload();
                        }
                    }
                }
            }
        }
    </script>
{% endblock %}
